package bod.engine.map.blocks;

import java.awt.image.BufferedImage;

public class BlockType {

	private byte			friction;
	private byte			density;
	private BufferedImage[]	image;
	private boolean			border;
	private boolean			liquid;
	private Back			defaultBack;

	public BlockType(byte friction, byte density, BufferedImage[] image,
			boolean border, boolean liquid, Back defaultBack) {
		this.friction = friction;
		this.density = density;
		this.image = image;
		this.border = border;
		this.liquid = liquid;
		this.defaultBack = defaultBack;
	}

	public byte getImageByBorder(int dt, int dl, int db, int dr) {
		if (this.border) {
			boolean top = dt == this.density;
			boolean lft = dl == this.density;
			boolean btm = db == this.density;
			boolean rgt = dr == this.density;
			byte border = (byte) (top ? lft ? btm ? rgt ? 15 : 11 : rgt ? 12
					: 5 : btm ? rgt ? 13 : 6 : rgt ? 7 : 1
					: lft ? btm ? rgt ? 14 : 8 : rgt ? 9 : 2 : btm ? rgt ? 10
							: 3 : rgt ? 4 : 0);
			return border;
		} else {
			return 0;
		}
	}

	public byte getFallSpeed() {
		return this.friction;
	}

	public byte getDensity() {
		return this.density;
	}

	public BufferedImage getImage(int i) {
		return this.image[i];
	}

	public boolean hasBorder() {
		return this.border;
	}

	public boolean isSolid() {
		return this.friction == 100;
	}

	public boolean isLiquid() {
		return this.liquid;
	}

	public Back defaultBack() {
		return this.defaultBack;
	}

}